package com.jboost.common.file;

import com.jboost.common.constant.CommonConstant;
import com.jboost.common.file.constant.FileHandleStatusEnum;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.util.List;

@Data
public class FileCommonVo {
    @ApiModelProperty("文件id")
    private String fileId;
    @ApiModelProperty("文件url")
    private String fileViewUrl;
    @ApiModelProperty("文件url")
    private String fileDownUrl;
    @ApiModelProperty("视频才有值：视频码率列表")
    private List<VideoBitrateVo> bitrateList;
    @ApiModelProperty("视频才有值：视频缩略图")
    private String screenshotUrl;
    @ApiModelProperty("视频才有值：视频播放格式")
    private String playExt;
    @ApiModelProperty(value = "视频、音频时长，单位秒")
    private Integer duration;
    @ApiModelProperty(value = "处理状态：processing-处理中；success-处理成功；fail-处理失败")
    private String handleStatus;
    private String handleStatus_dictText;

    public static FileCommonVo expiredFile() {
        FileCommonVo fv = new FileCommonVo();
        fv.setFileId(CommonConstant.EXPIRED_FILE_ID);
        fv.setFileViewUrl(CommonConstant.EXPIRED_FILE_URL);
        return fv;
    }

    public String getHandleStatus_dictText() {
        if (null == handleStatus){
            return null;
        }
        return FileHandleStatusEnum.getDescByCode(handleStatus);
    }

    /**
     * 获取视频的播放格式
     * @return
     */
    public String getPlayExt() {
        if(null == fileViewUrl){
            return null;
        }
        if (fileViewUrl.indexOf(".m3u8")>-1){
            return "application/x-mpegURL";
        }else {
            return "video/mp4";
        }
    }

}
